local OrgLinkUrl = require('orgmode.org.links.url')
describe('OrgLinkUrl', function()
  describe('File url', function()
    it('should parse absolute url', function()
      local result = OrgLinkUrl:new('/path/to/some/file.org')
      assert.are.same('/path/to/some/file.org', result.path)
      assert.are.same('/path/to/some/file.org', result:get_file_path())
      assert.is.Nil(result.target)
      assert.is.Nil(result.protocol)
    end)

    it('should parse relative url', function()
      local result = OrgLinkUrl:new('./path/to/relative/file.org')
      assert.are.same('./path/to/relative/file.org', result.path)
      assert.are.same('./path/to/relative/file.org', result:get_file_path())
      assert.is.Nil(result.target)
      assert.is.Nil(result.protocol)
    end)
    it('should parse absolute url with protocol', function()
      local result = OrgLinkUrl:new('file:/path/to/some/file.org')
      assert.are.same('/path/to/some/file.org', result.path)
      assert.is.Nil(result.target)
      assert.are.same('file', result.protocol)
    end)
    it('should parse relative url with protocol', function()
      local result = OrgLinkUrl:new('file:./path/to/relative/file.org')
      assert.are.same('./path/to/relative/file.org', result.path)
      assert.are.same('./path/to/relative/file.org', result:get_file_path())
      assert.is.Nil(result.target)
      assert.are.same('file', result.protocol)
    end)
    it('should return proper checks', function()
      local result = OrgLinkUrl:new('file:./path/to/relative/file.org')
      assert.is.False(result:is_id())
      assert.are.same('./path/to/relative/file.org', result:get_file_path())
    end)
  end)

  describe('Target url', function()
    it('should parse absolute url and target', function()
      local result = OrgLinkUrl:new('/path/to/some/file.org::*Headline')
      assert.are.same('/path/to/some/file.org', result.path)
      assert.are.same('/path/to/some/file.org', result:get_file_path())
      assert.are.same('*Headline', result.target)
      assert.is.Nil(result.protocol)
    end)
    it('should parse relative url and target', function()
      local result = OrgLinkUrl:new('./path/to/relative/file.org::*Headline')
      assert.are.same('./path/to/relative/file.org', result.path)
      assert.are.same('./path/to/relative/file.org', result:get_file_path())
      assert.are.same('*Headline', result.target)
      assert.is.Nil(result.protocol)
    end)
    it('should parse absolute url with protocol and target', function()
      local result = OrgLinkUrl:new('file:/path/to/some/file.org::*Headline')
      assert.are.same('/path/to/some/file.org', result.path)
      assert.are.same('/path/to/some/file.org', result:get_file_path())
      assert.are.same('*Headline', result.target)
      assert.are.same('file', result.protocol)
    end)
    it('should parse relative url with protocol and headline', function()
      local result = OrgLinkUrl:new('file:./path/to/relative/file.org::*Headline')
      assert.are.same('./path/to/relative/file.org', result.path)
      assert.are.same('*Headline', result.target)
      assert.are.same('file', result.protocol)
    end)
  end)

  describe('Id url', function()
    it('should parse id as path', function()
      local result = OrgLinkUrl:new('id:6f48b815-9d7a-413f-80b3-e52fb50f97d8')
      assert.are.same('6f48b815-9d7a-413f-80b3-e52fb50f97d8', result.path)
      assert.is.Nil(result:get_file_path())
      assert.is.Nil(result.target)
      assert.are.same('id', result.protocol)
    end)

    it('should parse id with target', function()
      local result = OrgLinkUrl:new('id:6f48b815-9d7a-413f-80b3-e52fb50f97d8::*Headline')
      assert.are.same('6f48b815-9d7a-413f-80b3-e52fb50f97d8', result.path)
      assert.is.Nil(result:get_file_path())
      assert.are.same('*Headline', result.target)
      assert.are.same('id', result.protocol)
    end)

    it('should return proper checks', function()
      local result = OrgLinkUrl:new('id:6f48b815-9d7a-413f-80b3-e52fb50f97d8')
      assert.is.True(result:is_id())
      assert.are.same('6f48b815-9d7a-413f-80b3-e52fb50f97d8', result:get_id())
    end)
  end)
end)
